/******************************************************************************
ISYS 1078 / 1079 — Information Retrieval
Assignment #1

Student Name: [ Rui, Wang ]
Student ID: [ 3171459 ]
CSIT username: [ rwang ]
*******************************************************************************/
#define BUF_SIZE 256

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "func.h"
	
#define DOC_LEN 50

typedef struct bucketNode *BucketList;
typedef struct bucketNode{
	char *term;
	int freq_t;
	int ppos;
	BucketList next;
	
}BucketNode;

typedef struct hashtable *HashTablePtr;
typedef struct hashtable{
	BucketList *head;
	int size;
}HashTable;


typedef struct mapNode *MapList;
typedef struct mapNode{
	int docId;
	char* docNum;
	MapList next;
}MapNode;

typedef struct docMap *DocTablePtr;
typedef struct docMap{
	MapList *head;
}DocMap;


int BuildSearchMap(HashTable *HT, DocMap *DM, FILE *fp_lex, FILE *fp_map);
int BuildHashTable(HashTable *HT, FILE *fp_lex);
int HashTableInit(HashTable *HT, FILE *fp_lex);
int HashFunc(char *str, int size);
void BucketInsert(HashTable *HT, Term *term);

int DocMapInit(DocMap *DM, FILE *fp_map);
int BuildDocMap(DocMap *DM, FILE *fp_map);
void DocBucketInsert(DocMap *DM, Doc *doc);

int Counter(FILE *fp, int mode);
int SearchIvtlists(int ppos, DocMap *DM, FILE *fp);
int Query(char* qterm, HashTable *HT, DocMap *DM, FILE *fp);

void DestroyHashTable(HashTable *HT, DocMap *DM);
void HashTableFree(HashTable *HT);
void BucketListFree(BucketList curr);
void DocMapFree(DocMap *DM);
void DocBucketListFree(MapList curr);



void ToUpperCase(char *str);
int PrimeSet(int x);
int IsPrime(int x);